package spotGUI.floatingChatGUI;

import java.awt.Component;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JToolBar;

import spotGUI.utils.EmptyContentAreaButton;
import java.awt.Cursor;
import java.util.ResourceBundle;


public class ChatToolBar extends JToolBar {

	private JButton btnEmoticons;
	private JButton btnFont;
	private JButton btnColor;
	private JButton btnTrill;
	private JButton btnSend;
	private JButton btnSendFile;
	private JButton btnExportconversation;

	private Component horizontalGlue;
	private Component horizontalGlue_1;
	private Component horizontalStrut;
	private Component horizontalStrut_1;
	private Component horizontalStrut_2;
	private Component horizontalStrut_3;
	private Component horizontalStrut_4;
	private Component horizontalStrut_5;

	private HashMap<String, JButton> featuresMap = new HashMap<String, JButton>();

	public ChatToolBar () {

		setFloatable(false);

		horizontalGlue = Box.createHorizontalGlue();
		add(horizontalGlue);

		btnEmoticons = new EmptyContentAreaButton(FloatingChatFrame.class.getResource("/images/Icons/48x48/twitter.png"), null);
		btnEmoticons.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		featuresMap.put("emoticons", btnEmoticons);
		btnEmoticons.setToolTipText(ResourceBundle.getBundle("spotGUI.floatingChatGUI.messages").getString("ChatToolBar.btnEmoticons.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		add(btnEmoticons);

		btnFont = new EmptyContentAreaButton(FloatingChatFrame.class.getResource("/images/Icons/48x48px/edit.png"), null);
		btnFont.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		featuresMap.put("font", btnFont);

		horizontalStrut_2 = Box.createHorizontalStrut(8);
		add(horizontalStrut_2);
		btnFont.setToolTipText(ResourceBundle.getBundle("spotGUI.floatingChatGUI.messages").getString("ChatToolBar.btnFont.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		add(btnFont);

		btnColor = new EmptyContentAreaButton(FloatingChatFrame.class.getResource("/images/Icons/48x48/chart.png"), null);
		btnColor.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		featuresMap.put("color", btnColor);

		horizontalStrut_3 = Box.createHorizontalStrut(8);
		add(horizontalStrut_3);
		btnColor.setToolTipText(ResourceBundle.getBundle("spotGUI.floatingChatGUI.messages").getString("ChatToolBar.btnColor.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		add(btnColor);

		horizontalStrut = Box.createHorizontalStrut(20);
		add(horizontalStrut);

		btnTrill = new EmptyContentAreaButton(FloatingChatFrame.class.getResource("/images/Icons/48x48/user_warning.png"), null);
		btnTrill.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		featuresMap.put("trill", btnTrill);
		btnTrill.setToolTipText(ResourceBundle.getBundle("spotGUI.floatingChatGUI.messages").getString("ChatToolBar.btnTrill.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		add(btnTrill);

		horizontalStrut_4 = Box.createHorizontalStrut(8);
		add(horizontalStrut_4);

		btnSend = new EmptyContentAreaButton(FloatingChatFrame.class.getResource("/images/Icons/48x48px/mail_send.png"), null);
		btnSend.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		featuresMap.put("send", btnSend);
		btnSend.setToolTipText(ResourceBundle.getBundle("spotGUI.floatingChatGUI.messages").getString("ChatToolBar.btnSend.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		add(btnSend);

		horizontalStrut_5 = Box.createHorizontalStrut(8);
		add(horizontalStrut_5);

		btnSendFile = new EmptyContentAreaButton(FloatingChatFrame.class.getResource("/images/Icons/48x48px/up.png"), null);
		btnSendFile.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		featuresMap.put("fileTransfer", btnSendFile);
		btnSendFile.setToolTipText(ResourceBundle.getBundle("spotGUI.floatingChatGUI.messages").getString("ChatToolBar.btnSendFile.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		add(btnSendFile);

		horizontalStrut_1 = Box.createHorizontalStrut(20);
		add(horizontalStrut_1);

		btnExportconversation = new EmptyContentAreaButton(FloatingChatFrame.class.getResource("/images/Icons/48x48/page_download.png"), null);
		btnExportconversation.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		featuresMap.put("exportConversation", btnSendFile);
		btnExportconversation.setToolTipText(ResourceBundle.getBundle("spotGUI.floatingChatGUI.messages").getString("ChatToolBar.btnExportconversation.toolTipText")); //$NON-NLS-1$ //$NON-NLS-2$
		add(btnExportconversation);

		horizontalGlue_1 = Box.createHorizontalGlue();
		add(horizontalGlue_1);

	}

	public void setExportconversationListener (ActionListener l) {
		btnExportconversation.addActionListener(l);
	}
	public void setSendFileListener (ActionListener l) {
		btnSendFile.addActionListener(l);
	}
	public void setSendListener (ActionListener l) {
		btnSend.addActionListener(l);
	}
	public void setTrillListener (ActionListener l) {
		btnTrill.addActionListener(l);
	}
	public void setColorListener (ActionListener l) {
		btnColor.addActionListener(l);
	}
	public void setEmoticonsListener (ActionListener l) {
		btnEmoticons.addActionListener(l);
	}
	public void setFontListener (ActionListener l) {
		btnFont.addActionListener(l);
	}

	public void setFeature (String feature, ActionListener l) {
		if (feature.equals("exportConversation"))
			btnExportconversation.addActionListener(l);
		else if (feature.equals("fileTransfer"))
			btnSendFile.addActionListener(l);
		else if (feature.equals("trill"))
			btnTrill.addActionListener(l);
		else if (feature.equals("color"))
			btnColor.addActionListener(l);
		else if (feature.equals("emoticons"))
			btnEmoticons.addActionListener(l);
		else if (feature.equals("font"))
			btnFont.addActionListener(l);
		else if (feature.equals("send"))
			btnSend.addActionListener(l);
		else
			throw new IllegalArgumentException("Not such feature exixts.");
	}


	public void enableFeatures (String feature, boolean enabled) {
		if (feature == "all") {
			Collection<JButton> features = featuresMap.values();
			Iterator<JButton> it = features.iterator();
			while (it.hasNext()) {
				it.next().setEnabled(enabled);
			}
			return;
		}
		
		JButton btn = featuresMap.get(feature);
		if (btn != null) {
			btn.setEnabled(enabled);
		}
		else {
			throw new IllegalArgumentException("Not such feature exixts.");
		}

	}






}
